import { createRouter, createWebHashHistory } from 'vue-router'

//配置路由规则：简单来说就是配置每个组件的访问路径
const routes = [
    {
        path:'/',
        // component:()=>import('../views/Login.vue')
        redirect:'/login'
    },
    {
        path:'/login',
        component:()=>import('../views/Login.vue')
    },
    {
        path:'/orderList',
        component:()=>import('../views/OrderList.vue')
    },
    {
        path:'/index',
        component:()=>import('../views/Index.vue')
    },
    {
        path:'/businessList',
        component:()=>import('../views/BusinessList.vue')
    },
    {
        path:'/businessInfo',
        component:()=>import('../views/BusinessInfo.vue')
    },
    {
        path:'/order',
        component:()=>import('../views/Order.vue')
    },
    {
        path:'/pay',
        component:()=>import('../views/Pay.vue')
    }
    ,
    {
        path:'/userAddress',
        component:()=>import('../views/UserAddress.vue')
    }
    ,
    {
        path:'/addUserAddress',
        component:()=>import('../views/AddUserAddress.vue')
    }
    ,
    {
        path:'/editUserAddress',
        component:()=>import('../views/EditUserAddress.vue')
    },
    {
        path:'/userInfo',
        component:()=>import('../views/UserInfo.vue')
    },
    {
        path:'/settings',
        component:()=>import('../views/Settings.vue')
    },
    {
        path:'/profile',
        component:()=>import('../views/Profile.vue')
    },
    {
        path:'/changePassword',
        component:()=>import('../views/ChangePassword.vue')
    },
    {
        path:'/search',
        component:()=>import('../views/Search.vue')
    },
    {
        path:'/register',
        component:()=>import('../views/Register.vue')
    },
    {
        path:'/paySelect',
        component:()=>import('../views/PaySelect.vue')
    },
    {
        path:'/appraise',
        component:()=>import('../views/Appraise.vue')
    },
    {
        path:'/vipcenter',
        component:()=>import('../views/VipCenter.vue')
    },
    {
        path: '/foodIntroduction',
        name: 'FoodIntroduction',
        component: () => import('../views/FoodIntroduction.vue')
    },
    {
        path:'/rankList',
        component:()=>import('../views/RankList.vue')
    },
    {
        path:'/dietRecipe',
        component:()=>import('../views/DietRecipe.vue')
    },
    {
        path:'/foodLevel',
        component:()=>import('../views/FoodLevel.vue')
    }

]
  
  const router = createRouter({
    history: createWebHashHistory(),
    routes
  })

  //路由守卫：发生路由之前执行的操作
  //登录权限认证：判断sessionStorage中是否存在user信息，如果有则方行，没有就路由到登录组件
  //to:路由去往的资源位置  from：路由发生的资源位置  next：放行,如果没有next就会阻塞
//   router.beforeEach((to,from,next)=>{
//     // console.log(to.path)  //   /login   /orderList
//     //配置放行的路径
//     let arr=['/','/login','/index','/register']
//     if(arr.indexOf(to.path)>=0){ //在数组中找去往的路由路径，如果找到返回该路径在数组中的索引位置，如果找不到返回-1
//         next();
//     }else{
//         let user=JSON.parse(sessionStorage.getItem('user'))
//         if(user!=null){//已经登录要放行
//             next();
//         }else{//未登录：路由到登录组件
//             alert("请先登录")
//             router.push("/login")
//         }
//     }
   
//   })
  export default router


